<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div>张三</div>
    <button>点我</button>
    <script>
      var btn = document.querySelector("button");
      var myname = document.querySelector("div");
      /* var flag = true;
      btn.onclick = function () {
        //把flag取反
        flag = !flag;
        //根据flag的值 改变 myname里面的名字
        if (flag) {
          //flag是true,名字是张三
          myname.innerHTML = "张三";
        } else {
          //flag是false,名字是李四
          myname.innerHTML = "李四";
        }
      }; */
      var num = 0;
      btn.onclick = function () {
        num++;
        switch (num) {
          case 1:
            myname.innerHTML = "李四";
            break;
          case 2:
            myname.innerHTML = "张三";
            break;
          case 3:
            myname.innerHTML = "王麻子";
            break;
          default:
            myname.innerHTML = "点击错误";
        }
        if (num == 3) {
          num = 0;
        }
      };
    </script>
  </body>
</html>
